package io.renren.modules.user.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.user.entity.TNomalDictionalEntity;
import io.renren.modules.user.service.TNomalDictionalService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-09 09:35:14
 */
@RestController
@RequestMapping("/tnomaldictional")
public class TNomalDictionalController {
    @Autowired
    private TNomalDictionalService tNomalDictionalService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:tnomaldictional:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tNomalDictionalService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:tnomaldictional:info")
    public R info(@PathVariable("id") Integer id){
		TNomalDictionalEntity tNomalDictional = tNomalDictionalService.getById(id);

        return R.ok().put("tNomalDictional", tNomalDictional);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:tnomaldictional:save")
    public R save(@RequestBody TNomalDictionalEntity tNomalDictional){
		tNomalDictionalService.save(tNomalDictional);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:tnomaldictional:update")
    public R update(@RequestBody TNomalDictionalEntity tNomalDictional){
		tNomalDictionalService.updateById(tNomalDictional);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:tnomaldictional:delete")
    public R delete(@RequestBody Integer[] ids){
		tNomalDictionalService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/listDictional")
 //   @RequiresPermissions("generator:tnomaldictional:list")
    public R listDictional(){
        List<TNomalDictionalEntity> tNomalDictionalEntities = tNomalDictionalService.listDictional();
        return R.ok().put("data",tNomalDictionalEntities);
    }

    /*
    * 籍贯
    * */
    @RequestMapping("/listCity")
    public R listCity(){
        List<TNomalDictionalEntity> tNomalDictionalEntities = tNomalDictionalService.list(new QueryWrapper<TNomalDictionalEntity>()
           .eq("type",1)
        );
        return R.ok().put("data",tNomalDictionalEntities);
    }



}
